package com.phb.puhuibao.web.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.idp.pub.service.IBaseService;
import com.idp.pub.web.controller.BaseController;
import com.phb.puhuibao.entity.ParTimeJobType;
import com.phb.puhuibao.service.MuserJobReleaseService;
import com.phb.puhuibao.service.ParTimeJobTypeService;

@Controller
@RequestMapping(value = "/parTimeJobType")
public class ParTimeJobTypeController extends BaseController<ParTimeJobType, String> {
	@Resource(name = "parTimeJobTypeService")
	public void setBaseService(IBaseService<ParTimeJobType, String> baseService) {
		super.setBaseService(baseService);
	}
	@Resource(name = "parTimeJobTypeService")
	private ParTimeJobTypeService parTimeJobTypeService;
	
	@Resource(name = "jdbcTemplate")
	private JdbcTemplate jdbcTemplate;
    /**
     * 获得所有兼职下属分支
     * @return
     */
	@RequestMapping(value="getParTimeJobType")
	@ResponseBody
	public Map<String, Object> getParTimeJobType() {
		
		Map<String, Object> data = new HashMap<String, Object>();
		Map<String,Object> retobj = null;
		List <Map<String, Object>> list = null;
		String sql="SELECT a.job_classtype,b.job_type_type FROM phb_part_time_job_type b LEFT JOIN phb_part_time_job a on a.parttime_job_id=b.parttime_job_id";
		try {
			list = this.jdbcTemplate.queryForList(sql);
			if (!list.isEmpty()) {
				data.put("result", list);
				data.put("message", "查询成功");
				data.put("status", 1);
			}else {
				data.put("message", "数据为空");
				data.put("status", 2);
			}
		} catch (DataAccessException e) {
			data.put("message", "网络异常");
			data.put("status", 0);
		}
		return data;
	}
	
	  /**
     * 热门搜索（首页搜索）
     * @return
     */
	@RequestMapping(value="getParTimeJobTypeBranch")
	@ResponseBody
	public Map<String, Object> getParTimeJobTypeBranch() {
		
		Map<String, Object> data = new HashMap<String, Object>();
		Map<String,Object> retobj = null;
		List <Map<String, Object>> list = null;
		String sql="SELECT parttime_job_type_id parttimeJobTypeId,job_type_type jobTypeType FROM phb_part_time_job_type WHERE parttime_job_id in ( SELECT distinct(a.job_type_type) FROM phb_muser_job_release a LEFT JOIN phb_part_time_job_type b on a.job_type=b.job_type_type ORDER BY a.create_time DESC ,a.access_amount DESC) LIMIT 0,8";
		try {
			list = this.jdbcTemplate.queryForList(sql);
			if (!list.isEmpty()) {
				data.put("result", list);
				data.put("message", "查询成功");
				data.put("status", 1);
			}else {
				data.put("message", "数据为空");
				data.put("status", 2);
			}
		} catch (DataAccessException e) {
			data.put("message", "网络异常");
			data.put("status", 0);
		}
		return data;
	}
	
	/**
     * 获得所有兼职下属分支
     * @return
     */
	@RequestMapping(value="getParTimeJobsType")
	@ResponseBody
	public Map<String, Object> getParTimeJobsType() {
		
		Map<String, Object> data = new HashMap<String, Object>();
		try {
			List<Map<String, Object>> list = parTimeJobTypeService.getParTimeJobsTypeSubordinate();
			if (!list.isEmpty()) {
				data.put("result", list);
				data.put("message", "查询成功");
				data.put("status", 1);
			}else {
				data.put("message", "数据为空");
				data.put("status", 2);
			}
		} catch (DataAccessException e) {
			data.put("message", "网络异常");
			data.put("status", 0);
		}
		return data;
	}
	
}
